package ua.yandex.skipasssystem.skipass.validators;

import ua.yandex.skipasssystem.skipass.PartOfDayInterface;
import ua.yandex.skipasssystem.skipass.SkiPass;

import java.time.LocalDateTime;

public class PartOfDayUnlimSkiPassValidator extends
        WithDaysOfWorkingSkiPassValidator {

    private PartOfDayUnlimSkiPassValidator() {

    }

    public static PartOfDayUnlimSkiPassValidator getValidator() {
        return ValidatorHolder.VALIDATOR_HOLDER;
    }

    public boolean validate(SkiPass skiPass,
                            LocalDateTime dateTime) {
        boolean isCorrectDateAndActive =
                super.validate(skiPass, dateTime);

        boolean isCorrectTime =
                ((PartOfDayInterface) skiPass).getFromTime().
                        isBefore(dateTime.toLocalTime())
                        && ((PartOfDayInterface) skiPass).getToTime().
                        isAfter(dateTime.toLocalTime());
        boolean isCorrectDayType = isWorkAtDay(skiPass, dateTime);

        return isCorrectDateAndActive && isCorrectTime && isCorrectDayType;
    }

    public static class ValidatorHolder {
        public static final PartOfDayUnlimSkiPassValidator VALIDATOR_HOLDER =
                new PartOfDayUnlimSkiPassValidator();
    }
}
